//
//  PersonDetailControl.m
//  FreeTime
//
//  Created by  on 16/8/25.
//  Copyright © 2016年 SRDZ.com. All rights reserved.
//

#import "SDCycleScrollView.h"
#import "PersonDetailControl.h"
#import "Header.h"
#import "PersonDetailCell.h"
#import "PayMoneyControl.h"
#import "ApplyQuoteControl.h"
#import "QuoteView.h"
@interface PersonDetailControl ()<SDCycleScrollViewDelegate>
{
    NSArray * dataArr;
    UIView * quoteView;
}

@end

@implementation PersonDetailControl

- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self loadOriData];
    [self setupUI];
    [self setupNav];
    
    
}
#pragma mark -- selfStyle --

- (void)setupUI{
    quoteView = [[UIView alloc] initWithFrame:self.view.bounds];
    quoteView.backgroundColor = [UIColor blackColor];
    quoteView.alpha = 0.4;
    UIView * bgView = [[UIView alloc] init];
    SDCycleScrollView * scrol = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, WindowWidth, 180) delegate:self placeholderImage:nil];
    scrol.localizationImageNamesGroup = @[@"123"];
    [bgView addSubview:scrol];
    CGFloat w = [ToolUtil autoWidth:@"脂肪在燃烧 31" width:0 height:15 num:14];
    UILabel * nameLbl = [ReduceCode creatLabelWithFrame:CGRectMake(10, CGRectGetMaxY(scrol.frame)+15, w, 15) title:@"脂肪在燃烧 31" titleColor:[ImageUtil colorWithRgb:0x4c4c4c] font:14 textAlignment:0];
    [bgView addSubview:nameLbl];
    UIImageView * sexImg = [ReduceCode creatImageVeiwWithFrame:CGRectMake(10, CGRectGetMaxY(nameLbl.frame)+5, 10, 10) imageName:@"nvsheng" isCorner:NO];
    sexImg.backgroundColor = DEBUG_CLOLR;
    [bgView addSubview:sexImg];
    CGFloat w1 = [ToolUtil autoWidth:@"3KM 35分钟前活跃" width:0 height:10 num:12];
    UILabel * timeLbl = [ReduceCode creatLabelWithFrame:CGRectMake(CGRectGetMaxX(sexImg.frame)+5, CGRectGetMaxY(nameLbl.frame)+5, w1, 10) title:@"3KM 35分钟前活跃" titleColor:[ImageUtil colorWithRgb:0xe6e6e6] font:12 textAlignment:0];
    [bgView addSubview:timeLbl];
    NSArray * imgArr = @[@"baojia",@"zuTA"];
    NSArray * titleArr = @[@"报价",@"租TA"];
    for (int i = 0; i<2; i++) {
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(WindowWidth-80*(i+1), CGRectGetMaxY(scrol.frame), 80, 61);
        [btn addTarget:self action:@selector(quoteBtn:) forControlEvents:UIControlEventTouchUpInside];
        UIImageView * btnImg = [ReduceCode creatImageVeiwWithFrame:CGRectMake(17.5, 20.5, 20, 20) imageName:imgArr[i] isCorner:NO];
        btn.tag = 300+i;
        [btn addSubview:btnImg];
        UILabel * btnLbl = [ReduceCode creatLabelWithFrame:CGRectMake(CGRectGetMaxX(btnImg.frame)+5, 20.5, 35, 20) title:titleArr[i] titleColor:HOME_COLOR font:14 textAlignment:0];
        [btn addSubview:btnLbl];
        if (i==1) {
            btnImg.frame = CGRectMake(7.5, 20.5, 20, 20);
            btnLbl.frame = CGRectMake(CGRectGetMaxX(btnImg.frame)+5, 20.5, 35, 20);
        }
        [bgView addSubview:btn];
    }
    [ToolUtil createVerticalLine:CGRectGetMaxY(scrol.frame)+20.5 superView:bgView lift:WindowWidth-80 height:20 color:[ImageUtil colorWithRgb:0xff596e]];
    CGFloat y = [ToolUtil createLine:CGRectGetMaxY(timeLbl.frame)+15 superView:bgView lift:10 width:WindowWidth-20 hight:1 color:[ImageUtil colorWithRgb:0xe6e6e6]];
    
    UILabel * onlineLbl = [ReduceCode creatLabelWithFrame:CGRectMake(10, y+20, 70, 15) title:@"线上技能" titleColor:[ImageUtil colorWithRgb:0x4c4c4c] font:14 textAlignment:0];
    CGFloat y1 = [ToolUtil createLine:CGRectGetMaxY(onlineLbl.frame)+5 superView:bgView lift:10 width:70 hight:1 color:[ImageUtil colorWithRgb:0xb3b3b3]];
    [bgView addSubview:onlineLbl];
    CGFloat y2 = 0;
    CGFloat w2 = (WindowWidth-60.5)/4;
    
    for (int i = 0; i<4; i++) {
        UILabel * lbl = [ReduceCode creatLabelWithFrame:CGRectMake(10+w2*i+i*13.5, y1+15, w2, 22) title:@"在线聊天" titleColor:[UIColor whiteColor] font:14 textAlignment:1];
        lbl.backgroundColor = HOME_COLOR;
        lbl.layer.cornerRadius = 5;
        lbl.layer.masksToBounds = YES;
        [bgView addSubview:lbl];
        y2=CGRectGetMaxY(lbl.frame);
    }
    
    UILabel * noLineLbl = [ReduceCode creatLabelWithFrame:CGRectMake(10, y2+20, 70, 15) title:@"线下技能" titleColor:[ImageUtil colorWithRgb:0x4c4c4c] font:14 textAlignment:0];
    CGFloat y3 = [ToolUtil createLine:CGRectGetMaxY(noLineLbl.frame)+5 superView:bgView lift:10 width:70 hight:1 color:[ImageUtil colorWithRgb:0xb3b3b3]];
    [bgView addSubview:noLineLbl];
    CGFloat y4 = 0;
    for (int i = 0; i<4; i++) {
        UILabel * lbl = [ReduceCode creatLabelWithFrame:CGRectMake(10+w2*i+i*13.5, y3+15, w2, 22) title:@"在线聊天" titleColor:[UIColor whiteColor] font:14 textAlignment:1];
        lbl.backgroundColor = HOME_COLOR;
        lbl.layer.masksToBounds = YES;
        lbl.layer.cornerRadius = 5;
        [bgView addSubview:lbl];
        y4 = CGRectGetMaxY(lbl.frame);
    }
    bgView.frame = CGRectMake(0, 0, WindowWidth, y4);
    self.tableView.frame = CGRectMake(0, 0, WindowWidth, WindowHeight-64-49);
    self.tableView.tableHeaderView = bgView;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[PersonDetailCell class] forCellReuseIdentifier:@"PersonDetailCell"];
    UIButton * payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    payBtn.frame = CGRectMake(0, WindowHeight-49-64, WindowWidth, 49);
    payBtn.backgroundColor = HOME_COLOR;
    [payBtn addTarget:self action:@selector(payBtn) forControlEvents:UIControlEventTouchUpInside];
    [payBtn setTitle:@"支付礼金" forState:UIControlStateNormal];
    [payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    payBtn.titleLabel.font = FONT(18);
    [self.view addSubview:payBtn];
    
}
- (void)loadOriData{
    dataArr = @[@"出租时间",@"我的信息",@"我的信息",@"简介"];
}

#pragma mark tableViewMethord
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 36.5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 45;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellIdentifier = @"PersonDetailCell";
    PersonDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 45)];
    UILabel * onlineLbl = [ReduceCode creatLabelWithFrame:CGRectMake(10, 20, 60, 15) title:dataArr[section] titleColor:[ImageUtil colorWithRgb:0x4c4c4c] font:14 textAlignment:0];
    [bgView addSubview:onlineLbl];
    [ToolUtil createLine:CGRectGetMaxY(onlineLbl.frame)+5 superView:bgView lift:10 width:60 hight:1 color:[ImageUtil colorWithRgb:0xb3b3b3]];
    return bgView;
}
#pragma mark -- popVC --
- (void)pop{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -- Button响应事件 --
//支付定金
- (void)payBtn{
    PayMoneyControl * payVC = [PayMoneyControl new];
    [self.navigationController pushViewController:payVC animated:YES];
}
- (void)quoteBtn:(UIButton *)btn{
    if (btn.tag == 300) {
//        QuoteView *view = [[QuoteView alloc]init];
//        [view show];
//        [self animationAlert:quoteView];

        [self.view addSubview:quoteView];
        ApplyQuoteControl * quoteVC = [ApplyQuoteControl new];
        quoteVC.view.frame = CGRectMake((WindowWidth-240)/2,80,240, 240);
        quoteVC.view.backgroundColor = [UIColor clearColor];
        quoteVC.view.layer.cornerRadius=3;
        quoteVC.view.layer.masksToBounds=YES;
        [ToolUtil animationAlert:quoteVC.view];
        [self addChildViewController:quoteVC];
        [self.view addSubview:quoteVC.view];
    }
}
@end
